﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpticalPowerMeter
{
    /// <summary>
    /// 串口参数，串口名、波特率
    /// </summary>
    public class SerialPortParam:IEquatable<SerialPortParam>
    {
        /// <summary>
        /// 端口名
        /// </summary>
        public string Portname { set; get; }

        /// <summary>
        /// 波特率
        /// </summary>
        public int Baudrate { set; get; }

        /// <summary>
        /// 重写对比方式
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns>两个对象的值是否一致</returns>
        public override bool Equals(object obj)
        {
            if(obj.GetType().Name.EndsWith("SerialPortParam"))
            {
                return Equals(obj as SerialPortParam);
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 重写获取Hash表的方式
        /// </summary>
        /// <returns>串口名、波特率的Hash表</returns>
        public override int GetHashCode()
        {
            return (Portname, Baudrate).GetHashCode();
        }

        public bool Equals(SerialPortParam other)
        {
            if (other is null) {
                return false;
            }
            return Portname == other.Portname && Baudrate == other.Baudrate;
        }
    }
}
